//
//  TasksMVM.swift
//  DianXia
//
//  Created by you&me on 2017/12/20.
//  Copyright © 2017年 you&me. All rights reserved.
//

import Foundation

class TasksVM {
    let provider = MoyaProvider<BCModuleApi>()
    let dispose = DisposeBag()
    let isReload = Variable(false)

    func acceptOrRefuseTask(_ actionType: String, _ no: Int, _ acceptModelIdx: Int)  {
       provider.rx.request(.acceptTask(actionType: actionType, mobile: UserManager.shareManager.userMobile ?? "", no: no))
               .retry(3)
               .asObservable()
               .mapModel(SupportModel.self)
               .subscribe(onNext: { (model) in
                    guard model.msg == "success" else {
                      return BCShowMessage.shareMessage.showTipMsg(model.result?.describe ?? "", time: 1)
                    }
                    if actionType == "acceptTask" {
                    UserTasks.share.tasks[acceptModelIdx].progress = "2"
                    UserActivingTasks.share.tasks.append(UserTasks.share.tasks[acceptModelIdx])
                    }else {
                       UserTasks.share.tasks.remove(at: acceptModelIdx)
                     }
                    self.isReload.value = true
               })
               .disposed(by: dispose)
    }
}

